Function.RegisterNamespace("System.IO.DirectoryStrategy");

System.IO.DirectoryStrategy.Node=function(){
    var fs=null;

    // IDirectoryStrategy Members
    this.Exists=function(path){
        if(!!path){
            return fs.existsSync(path)&&fs.statSync(path).isDirectory();
        }
        return false;
    };

    this.GetFiles=function(path){
        var files=[];
        if(this.Exists(path)){
            var fileList=fs.readdirSync(path);
            for(var i=0;i<fileList.length;i++){
                var absolutePath=System.IO.Path.Combine(path,fileList[i]);
                if(fs.statSync(absolutePath).isFile()){
                    files.push(absolutePath);
                }
            }
        }
        return files;
    };
    
    this.GetDirectories=function(path){
        var directories=[];
        if(this.Exists(path)){
            var directoryList=fs.readdirSync(path);
            for(var i=0;i<directoryList.length;i++){
                var absolutePath=System.IO.Path.Combine(path,directoryList[i]);
                if(fs.statSync(absolutePath).isDirectory()){
                    directories.push(absolutePath);
                }
            }
        }
        return directories;
    };

    // IStrategySpecification Members
    this.IsSatisfiedBy=function(candidate){
        if(Object.Global()==Object.Global().global&&typeof(process)!="undefined"&&typeof(require)=="function"){
            fs=require("fs");
            return true;
        }
        return false;
    };

};

System.IO.DirectoryStrategy.Node.Implement(System.IO.DirectoryStrategy.IDirectoryStrategy,'System.IO.DirectoryStrategy.Node');
System.IO.DirectoryStrategy.Node.Implement(System.Script.Strategy.IStrategySpecification,'System.IO.DirectoryStrategy.Node');

System.IO.Directory.Strategies.Add(System.IO.DirectoryStrategy.Node);